/*server-admin.cpp: This .cpp file controls the different phases needed to register, vote, compute votes, and display results*/
#include "project.h"

int main(int argc, char *argv[])
{
	if (argc != 2)
		return 0;
	MSG m;                    //from struct MSG
	int type;
	m.size = sizeof(int);                  //size of message
	m.data = &type;                       
	if (strcmp(argv[1], "--reg") == 0)           //case that server(CTF) can register voters
		MSG_TYPE(&m) = MSG_ADMIN_REG;
	else if (strcmp(argv[1], "--tally-keys") == 0)
		MSG_TYPE(&m) = MSG_ADMIN_TALLY_KEYS;   //case that tallys all message keys from administrator
	else if (strcmp(argv[1], "--vote") == 0)
		MSG_TYPE(&m) = MSG_ADMIN_VOTE;
	else if (strcmp(argv[1], "--tally") == 0)    //case that the CTF will compute all the votes
		MSG_TYPE(&m) = MSG_ADMIN_TALLY;
	else if (strcmp(argv[1], "--done") == 0)     //case that shows the ending results of the voting process
		MSG_TYPE(&m) = MSG_ADMIN_DONE;
	else
		return -1;
	if (send_recv(&m, NULL) == 0)                 //condition that if message was successful or failed to be recieved  
		printf("MSG sent.\n");
	else
		printf("ERROR sending MSG.\n");
	return 0;
}

